package cn.hrms.controller;

import cn.hrms.domain.Department;
import cn.hrms.domain.web.R;
import cn.hrms.domain.web.TableDataInfo;
import cn.hrms.service.IDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 部门接口
 *
 * @author xiaokai54
 * @date 2024/12/18
 */
@RestController
@RequestMapping("/admin/department")
public class DepartmentController extends BaseController {
	@Autowired
	private IDepartmentService departmentService;

	/**
	 * 查询部门列表
	 */
	@GetMapping("/list")
	public TableDataInfo list(Department department) {
		List<Department> list = departmentService.selectDepartmentList(department);
		return getDataTable(list);
	}

	/**
	 * 获取部门详细信息
	 */
	@GetMapping(value = "/{deptNo}")
	public R<Department> getInfo(@PathVariable("deptNo") Long deptNo) {
		return R.ok(departmentService.selectDepartmentByDeptNo(deptNo));
	}

	/**
	 * 新增部门
	 */
	@PostMapping
	public R<Void> add(@RequestBody Department department) {
		return toAjax(departmentService.insertDepartment(department));
	}

	/**
	 * 修改部门
	 */
	@PutMapping
	public R<Void> edit(@RequestBody Department department) {
		return toAjax(departmentService.updateDepartment(department));
	}

	/**
	 * 删除部门
	 */
	@DeleteMapping("/{deptNos}")
	public R<Void> remove(@PathVariable Long[] deptNos) {
		return toAjax(departmentService.deleteDepartmentByDeptNos(deptNos));
	}
}
